package edu.vt.ece.rt.quorum.messsages.types;

import org.jgroups.Address;
import org.jgroups.Message;

import edu.vt.ece.rt.dstm.Context;
import edu.vt.ece.rt.dstm.QObject;
import edu.vt.ece.rt.quorum.Cluster;
import edu.vt.ece.rt.quorum.ClustersManager;
import edu.vt.ece.rt.quorum.Resource;
import edu.vt.ece.rt.quorum.messsages.QMessage;
import edu.vt.ece.rt.quorum.messsages.QMessage.MessageType;
import edu.vt.ece.rt.quorum.util.Names;

/*
 * Message to node to join the Cluster
 * @author Sudhanshu
 */

public class MeasureCost extends QMessage implements Runnable {
	boolean req;				//Measure Request or Response
	Address dest;				//Used to create response

	public MeasureCost(boolean b, Address d) {
		super(MessageType.MeasureCost);
		req = b;
		dest = d;
	}

	@Override
	public void run() {
		if(req){		//Executes on receive on other end
			try {
				Address src = getSrcAddr();
				Cluster c = ClustersManager.getCluster(Names.base);
				c.send(new Message(src, new MeasureCost(false, dest)));
			} catch (Exception e) {
				e.printStackTrace();
			}		
		}else{
			ClustersManager.getdistance(dest);	//On coming back
		}
	}	
}
